package com.cd.university.config.security.validate.email;

import com.cd.university.config.security.impl.AbstractValidateCodeProcessor;
import com.cd.university.config.security.validate.ValidateCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.ServletWebRequest;

/**
 * 邮件的生成，校验，发送，以及保存
 * @author 陈栋
 * @create 2021/9/10 13:42
 */
@Component("emailValidateCodeProcessor")
public class EmailValidateCodeProcessor extends AbstractValidateCodeProcessor<ValidateCode> {

    @Autowired
    private EmailCodeSender emailCodeSender;

    /**
     * 邮件发送
     * @param request 请求（request）和响应（response）
     * @param validateCode 验证码实例
     * @throws Exception
     */
    @Override
    public void send(ServletWebRequest request,
                     ValidateCode validateCode) throws Exception {
        String email = request.getRequest().getParameter("email");
        emailCodeSender.send(email, validateCode.getCode());
    }
}
